import {
  legacy_createStore,
  applyMiddleware,
} from 'redux'
import logger from 'redux-logger'
import thunk from 'redux-thunk'

import {ALLSTATE,ALLACTION,SETLIST,ADDLIST,ADDLISTCTIONTYPE} from '../types/store.d'

const initialState = {
  list:[],
  carlist:[],
  ordePrice:""
}

 const reduer = (state:ALLSTATE = initialState, { type, payload }:ALLACTION) => {
  switch (type) {

  case SETLIST:
    state.list=payload;
    return { ...state}

  case ADDLIST:
    const newList = [...state.carlist]
    newList.push(payload)
    state.carlist = newList
    return { ...state}

  default:
    return state
  }
}

const store = legacy_createStore(reduer,applyMiddleware(logger,thunk))

export default store